package org.example.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import org.example.api.UserApi;
import org.example.common.Login;
import org.example.common.Result;
import org.example.model.User;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
public class UserController {

    @Reference(interfaceClass = UserApi.class, version = "1.0.0", check = false)
    private UserApi userApi;

    @PostMapping("/save")
    public Result<User> saveUser(@RequestBody User user) {
        return userApi.saveUser(user);
    }

    @GetMapping("/user/{userId}")
    public Result<User> getUserById(@PathVariable("userId") Long userId) {
        return userApi.getUserById(userId);
    }

    @PostMapping("/login")
    public Result<User> login(@RequestBody Login login) {
        return userApi.login(login.getUsername(), login.getPassword());
    }
}
